import { Zoom, Fullscreen, Scale, MapTheme, Logo,MouseLocation } from "@antv/l7";
function useControls(scene, map) {
  const controls = {}; //所有的控件都添加到这个对象
  controls.zoom = new Zoom({
    position: "topleft",
  });
  controls.fullscreen = new Fullscreen({
    position: "topright",
  });
  controls.scale = new Scale({
    position: "bottomright",
  });
  controls.mapTheme = new MapTheme({
    options: [
      {
        text: "白天导航地图",
        value: "mapbox://styles/mapbox/navigation-day-v1",
      },
      {
        text: "夜间导航地图",
        value: "mapbox://styles/mapbox/navigation-night-v1",
      },
      {
        text: "标记卫星图",
        value: "mapbox://styles/mapbox/satellite-streets-v12",
      },
      {
        text: "普通卫星图",
        value: "mapbox://styles/mapbox/satellite-v9",
      },
    ],
  });
  controls.logo = new Logo({
    img: "http://www.x-zd.com/themes/simpleboot3_web/public/web/images/image/logo_03.png",
    href: "http://www.x-zd.com",
  });
  controls.mouseLocation = new MouseLocation({
    position: "bottomright",
  })
  for (let key in controls) {
    scene.addControl(controls[key]);
  }
  //一开始隐藏scale
  controls.scale.hide();
  //监听zoom的变化 当zoom>5的显示 否则隐藏
  map.on("zoom", function () {
    let zoom = map.getZoom();
    if (zoom > 5) {
      controls.scale.show();
    } else {
      controls.scale.hide();
    }
  });
}
export default useControls;
